home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 June / MacFormat 25.iso / Shareware City / Developers / macgzip_03b2-src / macos / Posix / ThinkCPosix Sources / utime.c < prev   
Encoding:
C/C++ Source or Header  |  1995-01-09  |  1.1 KB  |  61 lines  |  [TEXT/MPS ]

  1. /* $Id: $ */
  2.  
  3.  
  4. /*
  5.  * Original from ThinkCPosix by Timothy Murphy <tim@maths.tcd.ie>,
  6.  * Trinity College Dublin
  7.  *
  8.  * Modified by SPDsoft <macspd@ivo.cps.unizar.es> to use Unix dates
  9.  * seconds from Mac 'Fri Jan  1 00:00:00 1904' to
  10.  * Un*x 'Thu Jan  1 00:00:00 1970':                    2082844800
  11.  */
  12.  
  13. #define    U2MSEC    2082844800
  14.  
  15. #include <utime.h>
  16. #include <errno.h>
  17.  
  18. /*
  19.  * Stupid CodeWarrior 1.0a1s does not defines these
  20.  */
  21.  
  22. #ifndef EACCES
  23. #define EACCES        (-54)
  24. #endif
  25. #ifndef ENOENT
  26. #define ENOENT        (-43)
  27. #endif
  28.  
  29. int utime (char *filename,struct utimbuf *times)
  30. {
  31.     CInfoPBRec cipbr;
  32.     HFileInfo *fpb = (HFileInfo*)&cipbr;
  33.     DirInfo *dpb = (DirInfo*)&cipbr;
  34.     unsigned char pname[256];
  35.     short err;
  36.  
  37.     strcpy((char*)pname, filename);
  38.     c2pstr((char*)pname);
  39.  
  40.     dpb->ioDrDirID = 0L;
  41.     fpb->ioNamePtr = pname;
  42.     fpb->ioVRefNum = 0;
  43.     fpb->ioFDirIndex = 0;
  44.     fpb->ioFVersNum = 0;
  45.     err = PBGetCatInfo(&cipbr, FALSE);
  46.     if (err != noErr) {
  47.         errno = ENOENT;
  48.         return -1;
  49.     }
  50.     dpb->ioDrDirID = 0L;
  51.     fpb->ioFlMdDat = times->modtime + U2MSEC;
  52.     fpb->ioFlCrDat = times->actime + U2MSEC;
  53.     err = PBSetCatInfo(&cipbr, FALSE);
  54.     if (err != noErr) {
  55.         errno = EACCES;
  56.         return -1;
  57.     }
  58.     return 0;
  59. }
  60.  
  61.